using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Weazel.Toad.Application.Forms
{
  public partial class AddOpbSlaveIpBlockForm : Weazel.Toad.Application.Forms.DialogBaseForm
  {
    private uint baseAddress;
    private uint highAddress;
    private uint interruptCount;
    private string name;
    private uint registerCount;

    public uint RegisterCount
    {
      get { return registerCount; }  
    }

    public uint BaseAddress
    {
      get { return baseAddress; }
    }

    public uint HighAddress
    {
      get { return highAddress; }
    }

    public uint InterruptCount
    {
      get { return interruptCount; }
    }

    public string IpBlockName
    {
      get { return name; }
    }

    protected override void OnClosing(CancelEventArgs e)
    {
      if (DialogResult == DialogResult.OK)
      {
        try
        {
          baseAddress = Convert.ToUInt32(baseAddressTextBox.Text, 16);          
        }
        catch (Exception)
        {
          string message = "Invalid base address";
          MessageBox.Show(message);
          e.Cancel = true;
          return;
        }

        try
        {
          highAddress = Convert.ToUInt32(highAddressTextBox.Text, 16);
        }
        catch (Exception)
        {
          string message = "Invalid high address";
          MessageBox.Show(message);
          e.Cancel = true;
          return;
        }

        if (baseAddress >= highAddress)
        {
          string message = "Base address >= high address";
          MessageBox.Show(message);
          e.Cancel = true;
          return;
        }

        registerCount = (uint)registersNumericUpDown.Value;
        interruptCount = (uint) interruptCountNumericUpDown.Value;
        name = ipBlockName.Text.ToString();
      }
    }

    public AddOpbSlaveIpBlockForm()
    {
      InitializeComponent();
    }
  }
}

